/**
 * *************************************
 * Copyright(c)2016 Dingdang Yixia 
 * All Rights Reserved.
 *
 * @File: FaceosNotifyServiceImpl.java
 * @Package: com.ddyx.service.impl
 * @Description:
 * 
 * @Version: V1.0
 * @Author: Yidong.Xiang
 * @Date: 2017年8月27日 下午7:27:14
 * 
 * *************************************
 */
package com.ddyx.service.impl;


import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.TextMessage;

import org.springframework.stereotype.Service;

import com.ddyx.entity.Customer;
import com.ddyx.entity.Face;
import com.ddyx.mapper.CustomerMapper;
import com.ddyx.mapper.FaceMapper;
import com.ddyx.service.IFaceNotifyService;
import com.ddyx.service.base.BaseSaveFaceNodifyService;

/**
 * @ClassName: FaceppNotifyServiceImpl.java
 * @Module: Face++人脸抓拍机集成模块
 * @Description: 从MQ服务器队列中获人脸识别图片
 * 
 * @author: Yidong.Xiang
 * @date: 2017年8月27日 下午7:27:14
 * 
 */
@Service("saveFaceNotifyServie")
public class SaveFaceNotifyServiceImpl extends BaseSaveFaceNodifyService implements IFaceNotifyService {

	@Resource
	FaceMapper faceMapper;
	@Resource 
	CustomerMapper customerMapper;	
	/* (non-Javadoc)
	 * @see com.ddyx.service.base.BaseNodifyService#doMessage(javax.jms.MapMessage)
	 */
	@Override
	public void doMessage(MapMessage mapMessage) {
		if(mapMessage==null)return;
		
		try {
//			String ipcId = mapMessage.getString("IPC_ID");//网络摄像头ID
//			String deviceId = mapMessage.getString("DeviceId");//摄像头主机设备ID
//			int blackId = mapMessage.getInt("BlackID");//识别名单ID
//			byte[] faceImage = mapMessage.getBytes("FaceImg");//人脸头像图片
//			byte[] fullImage = mapMessage.getBytes("FullImg");//人脸全景图片
//			float score = mapMessage.getFloat("Score");//比对分值
//			String searchResult = mapMessage.getString("SearchResult");//识别结果
//			String collectTime = mapMessage.getString("CollectTime");//抓拍时间
//			String imageUuid = MD5FileUtil.getMD5String(faceImage);//生成人脸头像MD5编码
//			String faceSessionNo = mapMessage.getString("FaceId");//人脸识别编码，一个人识别一次的标识码
			
			String snapId =mapMessage.getString("snap_id");
//			String ipcId = mapMessage.getString("ipc_id");
			byte[] faceImage = mapMessage.getBytes("face_image");
			byte[]fullImage = mapMessage.getBytes("full_image");
			int faceCount = mapMessage.getInt("face_count");
			String snapTime = mapMessage.getString("snap_time");
//			Long msec = mapMessage.getLong("msec");
//			String imageId = mapMessage.getString("image_id");
//			String targetFacetoken = mapMessage.getString("target_facetoken");
			String outerId = mapMessage.getString("outer_id");
			String facesetToken = mapMessage.getString("faceset_token");
			String faceToken = mapMessage.getString("face_token");
			String imageMd5 = mapMessage.getString("image_md5");
//			Double confidence = mapMessage.getDouble("confidence");
			String contactId = mapMessage.getString("contact_id");
//			String searchResult = mapMessage.getString("searchResult");
//			String receiveTime = mapMessage.getString("receiveTime");
			
			Face face = new Face();
			face.setSnapId(snapId);
			face.setFaceImage(faceImage);
			face.setFullImage(fullImage);
			face.setFaceCount(faceCount);
			face.setSnapTime(snapTime);
			face.setFaceToken(faceToken);
			face.setImageUuid(imageMd5);
			face.setContactId(contactId);
			face.setOuterId(outerId);
			face.setFacesetToken(facesetToken);
			face.setFaceUuid(contactId);
			faceMapper.insert(face);
			Customer customer = new Customer();
			customer.setContactId(contactId);
			customer.setHeadImage(imageMd5);
			customer.setSnapTime(snapTime);
			customer.setCustomerUuid(faceToken);
			customer.setIsvip(0);
			customer.setLastDateArrived(snapTime);
			if(null!=contactId && !"".equals(contactId)) {
				int hasContact = customerMapper.hasContact(contactId);
				if(hasContact==0)
					customerMapper.insert(customer);
			}
		} catch (JMSException e) {
			e.printStackTrace();
			return;
		}

	}

	/* (non-Javadoc)
	 * @see com.ddyx.service.base.BaseNodifyService#doMessage(javax.jms.TextMessage)
	 */
	@Override
	public void doMessage(TextMessage textMessage) {
		// TODO Auto-generated method stub

	}
	@Override
	public String getQueueName() {
		
		return "DDSaveFace";
	}

}
